package com.flyme.module.exam.client.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 题目难度枚举
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@Getter
public enum duanTypeEnum implements IEnum {

    bronze("bronze", 1),
    silver("silver", 2),
    gold("gold", 3),
    platinum("platinum", 4),
    diamond("diamond", 5);

    public Integer text;
    @EnumValue
    public String code;

    duanTypeEnum(String code, Integer text) {
        this.text = text;
        this.code = code;
    }

    duanTypeEnum(String code) {
        this.text = getText(code);
        this.code = code;
    }

    public static Integer getText(String code) {
        Integer v = 0;
        for (duanTypeEnum duanTypeEnum : values()) {
            if (duanTypeEnum.code.equals(code)) {
                v = duanTypeEnum.text;
                break;
            }
        }
        return v;
    }

    public static String getByCode(Integer text) {
        String v = "";
        for (duanTypeEnum duanTypeEnum : values()) {
            if (duanTypeEnum.text.equals(text)) {
                v = duanTypeEnum.name();
                break;
            }
        }
        return v;
    }

    public static String getName(String code) {
        String v = "";
        for (duanTypeEnum duanTypeEnum : values()) {
            if (duanTypeEnum.code.equals(code)) {
                v = duanTypeEnum.name();
                break;
            }
        }
        return v;
    }

    public static duanTypeEnum getEnum(String code) {
        for (duanTypeEnum duanTypeEnum : values()) {
            if (duanTypeEnum.code.equals(code)) {
                return duanTypeEnum;
            }
        }
        return null;
    }

    public static Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>();
        for (duanTypeEnum educationEnum : values()) {
            map.put(educationEnum.code, educationEnum.text);
        }
        return map;
    }

    public static void main(String[] args) {
        System.out.print(getByCode(2));
    }

    @Override
    public Serializable getValue() {
        return this.code;
    }

}
